// 引入 Mock.js
import Mock from 'mockjs';

// 模拟登录后端接口
Mock.mock('http://192.168.43.168:8081/user/login', 'post', (options) => {
  const { id, password } = JSON.parse(options.body); // 从请求中获取用户名和密码

  // 根据用户名和密码模拟后端验证过程
  if (id === 'wyq' && password === '123456') {
    return Mock.mock({
      code: 200,
      data: {
        token: 'eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzNjY2ZmRkNDlmZTE0NzIyOGEwYTFlZmJkYTA3MWRmYyIsInN1YiI6IjIwMjEwOTA2MzJbe1JPTEVfS0VZPWFkbWlufV0iLCJpc3MiOiJ3ZHgzMDA0IiwiaWF0IjoxNzAxODUyMjc3LCJleHAiOjE3MDE4NTU4Nzd9.HHVsDyHrQrq-5iVFeMDfPQv9Wx90SSlcL4OAJbKWi28'
      }
    });
  } else {
    return Mock.mock({
      code: 401,
      msg: '账号或者密码错误'
    });
  }
});

//用户数据
const userData = [
    { id: 1, username: '张三', state: '激活', phone: '123456789', identity: '1234567890',role:'admin'},
    { id: 2, username: '李四', state: '未激活', phone: '987654321', identity: '0987654321',role:'student'},
    { id: 3, username: '王五', state: '激活', phone: '987654321', identity: '0987654321',role:'teacher'},
    { id: 4, username: '赵六', state: '未激活', phone: '987654321', identity: '0987654321',role:'student'}

    // 其他用户数据...
  ];
  const roleData = [
    { UTID: 1, USERNAME: '张三', state: '激活', phone: '123456789', identity: '1234567890',RNAME:'admin'},
    { id: 2, username: '李四', state: '未激活', phone: '987654321', identity: '0987654321',role:'student'},
    { id: 3, username: '王五', state: '激活', phone: '987654321', identity: '0987654321',role:'teacher'},
    { id: 4, username: '赵六', state: '未激活', phone: '987654321', identity: '0987654321',role:'student'}

    // 其他用户数据...
  ];
  // 使用 Mock.js 模拟后端数据
  Mock.mock('http://192.168.43.168:8081/Admin/selectList', 'get', {
    data: userData
  });
  Mock.mock('http://192.168.43.168:8081/Admin/selectRole', 'get', {
    data: roleData
  });


// 使用 Mock.js 定义模拟宿舍数据规则
// const dormdata = Mock.mock({
//   'data|10': [
//     {
//       'id|+1': 1,
//       'dormId|100-999': 1,
//       'dormBuildid|1-10': 1,
//       'reside_count|0-5': 1,
//       'contain_count|5-10': 1,
//     },
//   ],
// });
// console.log(dormdata);
// Mock.mock('http://192.168.43.168:8081/Dorm/selectList', 'get', {
//   data: dormdata
// });
// 模拟学生数据
const studentData = Mock.mock({
  'data|10': [
    {
      'SNO|+1': 10001,
      SNAME: '@cname',
      DROMSTATE: '@boolean',
      SSEX: '@pick(["男", "女"])',
      DORM_ID: '@integer(100, 999)',
      MAJOR_NAME: '@ctitle(5, 10)'
    }
  ]
});
console.log(studentData);
// 模拟接口
Mock.mock('http://192.168.43.168:8081/StuDorm/selectList', 'get',{
      data: studentData
});

  // 定义模拟数据
  const adminData = [
    {
      id: '2021090632',
      username: '张三',
      phone: '13888888888',
      email: 'zhangsan@example.com',
      address: '北京市海淀区',
      avatar: 'https://picsum.photos/id/237/200/200'
    },
    {
      id: '002',
      username: '李四',
      phone: '13999999999',
      email: 'lisi@example.com',
      address: '上海市浦东新区',
      avatar: 'https://picsum.photos/id/238/200/200'
    },
    // 可以继续添加其他管理员的数据
  ];
  
  // 使用 Mock.js 模拟后端接口
  Mock.mock('http://192.168.43.168:8081/Admin/selectbyID', 'get', function(options) {
    const userid = options.params.userid;
    const admin = adminData.find(a => a.id === userid);
    if (admin) {
      return {
        code: '200',
        msg: '获取管理员信息成功',
        data: admin
      };
    } else {
      return {
        code: '404',
        msg: '管理员不存在',
        data: null
      };
    }
  });
  
 